package com.e.dianshang.controller;

import com.e.dianshang.pojo.Spu;
import com.e.dianshang.service.SpuService;
import com.e.dianshang.utils.BusinessException;
import com.e.dianshang.utils.JsonResult;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @Author Tian同學
 * @Date 2020/11/9 17:58
 * @Version 1.0
 */
@RestController
@RequestMapping("/guiGe")
@Api(value = "商品规格",tags = "该商品规格的api")
public class SpuController {

    @Resource
    SpuService spuService;

    @PostMapping("/get")
    @ApiOperation(value = "该商品规格接口",httpMethod = "POST")
    @ApiImplicitParam(name = "goodsId",value = "商品ID",required = true,dataType = "int",paramType = "query")
    public Map get(@RequestParam("goodsId") Integer goodsId) throws BusinessException {

        JsonResult jsonResult=new JsonResult();

        List<Spu> guiGes = spuService.get(goodsId);

        if (!guiGes.isEmpty()){
            jsonResult.setCode("0");
            jsonResult.setData(guiGes);
        }else {
            throw new BusinessException("查询失败");
        }

        return  jsonResult.getValues();
    }

}
